<?php
namespace Blind\Controller;
use Think\Controller;
class ShowController extends Controller {

	//跳转到演出类页面
    public function showList()
    {
        $res = M('show') -> select();
        $this -> assign('data', $res);
        $this -> display();
    }

    public function showAdd()
    {
		$this -> display();
    }

    public function doshowAdd()
    {
        //获取所有传过来的数据
        $data['name'] = I('post.name');
        $data['introduce'] = I('post.introduce');
        $ruHour = I('post.ruHour');
        $rumin = I('post.rumin');
        $starttHour = I('post.startHour');
        $starttmin = I('post.startmin');
        $endHour = I('post.endHour');
        $endmin = I('post.endmin');
        $data['rutime'] = $ruHour.':'.$rumin;
        $data['starttime'] = $starttHour.':'.$starttmin;
        $data['endtime'] = $endHour.':'.$endmin;
        $res = M('show') -> add($data);
        if($res)
        {
            $this -> success('添加成功', 'showList');
        }else
        {
            $this -> error('添加失败');
        }
    }

    public function showDel($id)
    {
        $res = M('show') -> where("id=%d",$id) -> delete();
        if($res)
        {
            $this -> success('成功');
        }else
        {
            $this -> error('失败');
        }
    }


        //编辑广告
    public function updShow()
    {
        $data['name'] = I('post.name');
        
        $ruHour = I('post.ruHour');
        $rumin = I('post.rumin');
        $starttHour = I('post.startHour');
        $starttmin = I('post.startmin');
        $endHour = I('post.endHour');
        $endmin = I('post.endmin');
        $data['rutime'] = $ruHour.':'.$rumin;
        $data['starttime'] = $starttHour.':'.$starttmin;
        $data['endtime'] = $endHour.':'.$endmin;
        $data['introduce'] = I('post.introduce');
        $id = I('post.id');

        $res = M('show') -> where("id=%d",$id)-> save($data);
        if($res)
        {
            $this -> success('成功', 'showList');
        }else
        {
            $this -> error('失败');
        }
    }

    //编辑时获取单个广告的信息
    //
    public function findShow($id)
    {

        $res = M('show') -> where("id=%d",$id) -> select();
        $rutime = $res[0]['rutime'];
        $starttime = $res[0]['starttime'];
        $endtime = $res[0]['endtime'];
        $starttime = explode(':',$starttime); 
        $endtime = explode(':',$endtime); 
        $rutime = explode(':',$rutime); 
        $res[0]['startHour'] = $starttime[0];
        $res[0]['startMin'] = $starttime[1];
        $res[0]['ruHour'] = $rutime[0];
        $res[0]['ruMin'] = $rutime[1];
        $res[0]['endHour'] = $endtime[0];
        $res[0]['endMin'] = $endtime[1];

        if($res)
        {
            $this -> assign('data', $res);
            $this -> display();
        }else
        {
            $this -> error('编辑失败');
        }

    }

}